<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        html,body {
            width: 100%;
            height: 100%;
        }
        .ball {
            position: absolute;
            width: 30px;
            height: 30px;
            background-color:orange;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div class="ball"></div>
    <script src="jquery-3.3.1.js"></script>
    <script>
        var ball = $('.ball');
         $(document).keydown(function(e) {
             var step = 10
            switch(e.keyCode) {
                // 左37
                
                case 37:
                    console.log(parseInt(ball.css('width')) + 10)
                    ball[0].style.left += '-' + (parseInt(ball.css('left')) - step) + 'px';
                break;
                // 上38
                case 38:
                    ball[0].style.top += '-' + (parseInt(ball.css('top')) - step) + 'px';
                break;
                // 右39
                case 39:
                    ball[0].style.left +=  (parseInt(ball.css('left') + step)) + 'px';
                break;
                // 下40
                case 40:
                    ball[0].style.top +=  (parseInt(ball.css('top') + step)) + 'px';
                break;
                default: 
                    console.log('错误按键');
                break;
            }
        })


    </script>
</body>
</html>